/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hcmus.fit.master.sevensea.control;

import hcmus.fit.master.sevensea.core.Constant;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

/**
 * 
 * @author hvp
 */
public class Level {
    public static List<Bitmap> Resources;
    public int LEVEL;
    public static Bitmap Icon;

    public Level(int level) {
        LEVEL = level;
    }

    public void Show(Canvas g, int x, int y) {
        List<Integer> list = new ArrayList<Integer>();
        int level = LEVEL;
        while (level > 0) {
            list.add(new Integer(level % 10));
            level /= 10;
        }
        if (list.size() <= 0)
            list.add(new Integer(0));
        x -= (list.size() * 14);
        g.drawBitmap(Icon, x - 25, y - 5, new Paint());

        for (int i = 0; i < list.size(); i++) {
            int num = ((Integer) list.get(list.size() - i - 1)).intValue();

            Bitmap tmp = (Bitmap) Resources.get(num);
            int w = tmp.getWidth();
            // int h = tmp.getHeight();
            g.drawBitmap(tmp, x + i * w, y, new Paint());
        }

    }

    public static List<Bitmap> GetResource(Bitmap resource, int maxX, int maxY, int numerator,
            int denominator) {
        List<Bitmap> rs = new ArrayList<Bitmap>();
        int w = resource.getWidth() / maxX;
        int h = resource.getHeight() / maxY;

        for (int i = 0; i < maxY; i++) {
            for (int j = 0; j < maxX; j++) {
                Bitmap tmp = Bitmap.createBitmap(w, h, Constant.BITMAP_CONFIG);
                Canvas g = new Canvas(tmp);
                g.drawBitmap(resource, 0, 0, new Paint());
                rs.add(tmp);
            }
        }
        return rs;
    }
}
